#include <bits/stdc++.h>
#define ll long long
using namespace std;

int T,a,b;

int main(){
    freopen("sub.in","r",stdin);
    freopen("sub.out","w",stdout);
    scanf("%d",&T);
    while(T--){
        scanf("%d%d",&a,&b);
         if(1ll*a*b>=0) puts("0");
         else{
            int k=(a+b);
            int s=0;
            if(k>0) k/=max(a,b),s=max(a,b);
            else k/=min(a,b),s=min(a,b);
            int ans=min(abs(a+b-1ll*k*s),abs(a+b-1ll*(k+1)*s));
            printf("%d\n",ans);
         }
    }

//    system("pause");
    return 0;
}
/*
5
1 -1
3 -7
-4 -1
-5 8
4 0

1
6 -2
*/